﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ProjectCommon2.Wcf.Behaviors;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace PolePosition.v3.ServiceProxy
{
    public class VendorService
    {
        #region Static Reference to the VendorService

        private static string m_ServiceEndpointFileName = "Vendor.svc";

        internal static VendorServiceReference.VendorClient GetServiceClient()
        {
            Binding _Binding;
            EndpointAddress _EndPointAddress;

            _Binding = Setup.Binding;
            _EndPointAddress = Setup.GetEndPointAddress(m_ServiceEndpointFileName);

            VendorServiceReference.VendorClient _ServiceClient;
            _ServiceClient = new VendorServiceReference.VendorClient(_Binding, _EndPointAddress);

            _ServiceClient.Endpoint.Behaviors.Add(new AddUserCreatedModifiedClientHeaderBehavior());
            _ServiceClient.Endpoint.Behaviors.Add(new PushContextClientBehavior());

            // Update the data contract serializer for the operations to avoid max limit of objects in graph issue
            MaxDataContractSerializerOperationBehavior.ReplaceDataContactSerializer(_ServiceClient.Endpoint.Contract.Operations);

            //insert additional logic here?
            return _ServiceClient;
        }

        #endregion

        
        #region Calls to old v2.1 webservice -- all these need to be rewritten

        static private v21Service.Service1 m_OldService = null;
        static private v21Service.Service1 OldService
        {
            get
            {
                if (m_OldService != null)
                    return m_OldService;

                // construct service
                m_OldService = new v21Service.Service1();

                return m_OldService;
            }
        }

        public static string GetXmissionInspectionDatabasePath(int utilityId, string utilityName, int vendorId, string vendorName, int projectId, string projectName, int inspectorId, string inspectorName)
        {
            //old method signature
            //StartDeployInspection(int handheldId, string handheldName, int inspectorId, string inspectorName, int companyId, string companyName, string mobileVersion, int vendorId, string vendorName, int projectId, string projectName, int contactId, string contactName)
            //  eliminated handheld info, eliminated inspector info, changed company to utility, eliminated mobileVersion, changed contact to inspector

            return OldService.Deploy_StartDeployInspection(-1, null, -1, null, utilityId, utilityName, "BETA", "1", vendorId, vendorName, projectId, projectName, inspectorId, inspectorName);
        }


        public static string GetDistributionInspectionDatabasePath(int vendorId, string vendorName, int inspectorId, string inspectorName)
        {
            //distributionAppMode: 1 for Insp, 0 for GPS
            //return OldService.Deploy_StartDeployDistribution_Vendor("BETA", 1, vendorId, vendorName, inspectorId, inspectorName);
            return string.Empty;
        }

        public static string GetDistributionGPSDatabasePath(int vendorId, string vendorName, int inspectorId, string inspectorName)
        {
            //distributionAppMode: 1 for Insp, 0 for GPS
            //return OldService.Deploy_StartDeployDistribution_Vendor("BETA", 0, vendorId, vendorName, inspectorId, inspectorName);
            return string.Empty;
        }

        public static string GetXmissionGPSDatabasePath(int utilityId, string utilityName, int vendorId, string vendorName, int projectId, string projectName, int inspectorId, string inspectorName)
        {
            return OldService.Deploy_StartDeployGPS(utilityId, utilityName, vendorId, vendorName, projectId, projectName, inspectorId, inspectorName, -1, null, "BETA", "1");
        }

        #endregion
        



    }
}
